package com.cskaoyan.utils;


import java.math.BigDecimal;

/**
 * @author: lsy
 * @class: IntegraleUtil
 * @description: 积分抵扣
 */
public class IntegraleUtil {

    /**
     * @author: lsy
     * @title: getIntegralePrice
     * @description:
     * goodsPrice: 订单总金额
     * integrale: 用户拥有的积分
     * @param: [goodsPrice, integrale]
     * @return: java.math.BigDecimal
     */
    public static BigDecimal getIntegralePrice(BigDecimal goodsPrice, int integrale) {
        BigDecimal integraleBigDecimal = new BigDecimal(integrale);
        BigDecimal divide = goodsPrice.divide(new BigDecimal(10),2,BigDecimal.ROUND_UP);
        if (divide.compareTo(integraleBigDecimal) < 0) {
            // 只能扣divide的钱
            return divide;
        } else {
            return integraleBigDecimal;
        }
    }
}
